#include<bits/stdc++.h>
using namespace std;
const int N=5e3+10;
int c,n,x,m,ans,fa[N],dep[N];
vector<int> edge[N];
inline void dfs(int u,int f,int &x){
	if(dep[u]>=dep[x]) x=u;
	for(auto &i:edge[u])
		if(i!=f){
			dep[i]=dep[u]+1;
			dfs(i,u,x);
		}
}
inline int check(int u,int v){
	int now=u;
	while(now){
		if(now==v) return 0;
		now=fa[now];
	}
	now=v;
	while(now){
		if(now==u) return 0;
		now=fa[now];
	}
	return 1;
}
inline int get(){
	int u=0,v=0;
	dep[1]=0,dfs(1,0,u);
	dep[u]=0,dfs(u,0,v);
	return dep[v];
}
inline void cg(int u,int x,int y){
	vector<int> res;
	for(auto &i:edge[u])
		if(i!=x) res.push_back(i);
	res.push_back(y);
	edge[u]=res;
}
inline void swp(int x,int y){
	vector<int> res1,res2;
	res1.clear(),res2.clear();
	for(auto &i:edge[x])
		if(i!=fa[x]) res1.push_back(i),cg(i,x,y);
	for(auto &i:edge[y])
		if(i!=fa[y]) res2.push_back(i),cg(i,y,x);
	res1.push_back(fa[y]),res2.push_back(fa[x]);
	edge[y]=res1,edge[x]=res2;
}
inline void work(){
	ans=get();
	for(int i=1;i<=m;i++)
		for(int j=i+1;j<=m;j++){
			if(!check(i,j)) continue;
			swp(i,j);
			ans=max(ans,get());
			swp(i,j);
		}
}
signed main(){
	freopen("forest.in","r",stdin);
	freopen("forest.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>c>>n;
	for(int i=2;i<=n;i++){
		cin>>x;
		x^=ans,edge[x].push_back(i),edge[i].push_back(x),fa[i]=x,m=i;
		work();
		cout<<ans<<"\n";
	}
	return 0;
}